package org.sage.sdk.dada.order.aggregate;

import lombok.Getter;
import lombok.Setter;
import org.sage.sdk.dada.infrastructure.common.annotation.Aggregate;
import org.sage.sdk.dada.infrastructure.common.exception.MissingParameterException;
import org.sage.sdk.dada.infrastructure.common.attributes.*;

import javax.validation.constraints.NotNull;

/**
 * 收货人
 *
 * @author 周广明
 * @version v1 2019/12/10 下午4:48
 */
@Getter
@Setter
@Aggregate
public class Receiver {

    public Receiver(ReceiverAddress address, ReceiverLat lat,
                    ReceiverLng lng, ReceiverName name, ReceiverPhone phone) {
        this.address = address;
        this.lat = lat;
        this.lng = lng;
        this.name = name;
        this.phone = phone;
    }


    public Receiver(ReceiverAddress address, ReceiverLat lat,
                    ReceiverLng lng, ReceiverName name, ReceiverTel tel) {
        this.address = address;
        this.lat = lat;
        this.lng = lng;
        this.name = name;
        this.tel = tel;
    }

    public Receiver(ReceiverAddress address, ReceiverLat lat,
                    ReceiverLng lng, ReceiverName name, ReceiverPhone phone, ReceiverTel tel)
            throws MissingParameterException {

        if (phone == null && tel == null) {
            throw new MissingParameterException("手机号和座机号必填一项!");
        }

        this.address = address;
        this.lat = lat;
        this.lng = lng;
        this.name = name;
        this.phone = phone;
        this.tel = tel;
    }

    @NotNull
    ReceiverAddress address;

    @NotNull
    ReceiverLat lat;

    @NotNull
    ReceiverLng lng;

    @NotNull
    ReceiverName name;

    ReceiverPhone phone;

    ReceiverTel tel;

}
